<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css"
        integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog=="
        crossorigin="anonymous" />
    <title>Background Slider</title>
    <script>
        window.onload = function(){
            const body = document.body
            const slides = document.querySelectorAll('.slide')
            const leftBtn = document.getElementById('left')
            const rightBtn = document.getElementById('right')


            let activeSlide = 0
            rightBtn.addEventListener('click',()=>{
                activeSlide++

                if(activeSlide > slides.length-1){
                    activeSlide = 0
                }

                setBgToBody()
                setActiveSlide()
            })

            leftBtn.addEventListener('click',()=>{
                activeSlide--

                if(activeSlide < 0){
                    activeSlide = slides.length-1
                }

                setBgToBody()
                setActiveSlide()
            })

            setBgToBody()

            function setBgToBody(){
                body.style.backgroundImage = slides[activeSlide].style.backgroundImage
            }

            function setActiveSlide(){
                slides.forEach(slide=>slide.classList.remove('active'))
                slides[activeSlide].classList.add('active')
            }
            
        }
    </script>
    <style>
        *{
            box-sizing: border-box;
        }

        body{
            font-family: 'Roboto',sans-serif;
            display: flex;
            flex-direction:column ;
            align-items: center;
            justify-content: center;
            height: 100vh;
            overflow: hidden;
            margin: 0;
            background-position: center center;
            background-size: cover;
            transition: 0.4s all;
        }
        body::before{
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100vh;
            background-color: rgba(0, 0, 0, 0.7);
            z-index: -1;
        }

        .slider-container{
            box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16),3px 6px rgba(0, 0, 0, 0.23);
            height: 70vh;
            width: 70vw;
            position: relative;
            overflow: hidden;
        }

        .slide{
            opacity: 0;
            height:100vh;
            width: 100vw;
            background-position: center center;
            background-color: cover;
            position: absolute;
            top: -15vh;
            left: -15vw;
            transition: 0.4s ease;
            z-index: 1;
        }

        .slide.active{
            opacity: 1;
        }

        .arrow{
            position: fixed;
            background-color: transparent;
            color: #fff;
            padding: 20px;
            font-size: 30px;
            border: 2px solid orange;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
        }
        .arrow:focus{
            outline: 0;
        }
        .left-arrow{
            left: calc(15vw - 65px);
        }
        .right-arrow{
            right: calc(15vw - 65px);
        }
    </style>
</head>

<body>
    <div class="slider-container">
        <div class="slide active" style="background-image: url('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F2018-03-14%2F5aa8e05ac9c20.jpg%3Fdown&refer=http%3A%2F%2Fpic1.win4000.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653913641&t=ea71b824ccd3cd77921e5c94af387dc6');"></div>
        <div class="slide" style="background-image: url('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.jj20.com%2Fup%2Fallimg%2F811%2F040915120S0%2F150409120S0-12.jpg&refer=http%3A%2F%2Fpic.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653914029&t=73bac0a2fc8031746fa0d02fd1c6eab3');"></div>
        <div class="slide" style="background-image: url('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2F2018-06-15%2F5b236a18acfc0.jpg&refer=http%3A%2F%2Fpic1.win4000.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653914029&t=3468faeee1f3dbc267e900566153a919'); "></div>
        <div class="slide" style="background-image: url('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1113%2F033120122032%2F200331122032-2-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653914029&t=ab23b6be21e582a3b57d25afd8910950');"></div>
        <div class="slide" style="background-image: url('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F911%2F050416131024%2F160504131024-7-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653914029&t=8b836795a644a5ec61c189b8d26689f2');"></div>

        <button class="arrow left-arrow" id="left">
            <i class="fas fa-arrow-left"></i>
        </button>

        <button class="arrow right-arrow" id="right">
            <i class="fas fa-arrow-right"></i>
        </button>
    </div>
</body>

</html>